﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WoSoft.PACS.Data.CheckItem;

namespace WoSoft.PACS.Win.Forms.SubForms
{
    public partial class FrmCheckItem : FrmBase
    {
        private CheckItemDataService checkItemDataService = new CheckItemDataService();
        private string _FLID;
        private string _ID;

        public FrmCheckItem(string flid, string id)
        {
            InitializeComponent();
            _FLID = flid;
            _ID = id;
        }

        //保存确定
        private void buttonX1_Click(object sender, EventArgs e)
        {
            this.errorProvider1.Clear();
            if (this.tbxmmc.Text.Trim() == string.Empty)
            {
                this.errorProvider1.SetError(this.tbxmmc, "请填写项目名称");
                return;
            }

            var cnt = 0;
            if (string.IsNullOrEmpty(this._ID))
            {
                //增加
                cnt = checkItemDataService.CheckItemInsert(this._FLID, this.tbxmmc.Text.Trim(), this.tbxmjm.Text.Trim(), this.cbSex.SelectedValue.ToString(), this.tbxmfy.Text.Trim(), this.tbxmms.Text.Trim(), Program.CurrentLoginUser.Name, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            }
            else
            {
                //更新
                cnt = checkItemDataService.CheckItemUpdate(this._ID, this._FLID, this.tbxmmc.Text.Trim(), this.tbxmjm.Text.Trim(), this.cbSex.SelectedValue.ToString(), this.tbxmfy.Text.Trim(), this.tbxmms.Text.Trim(), Program.CurrentLoginUser.Name, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            }

            if (cnt>0)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
        }

        //取消关闭
        private void buttonX2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmOutlineWords_Load(object sender, EventArgs e)
        {
            //加载性别列表
            LoadSexList(this.cbSex);
            //设置拼音自动显示
            this.SetSpellCodeControl(this.tbxmmc, this.tbxmjm);

            if (string.IsNullOrEmpty(this._ID)) return;
            var dt = checkItemDataService.GetCheckItemByID(this._ID);
            if (dt.Rows.Count > 0)
            {
                this.tbxmmc.Text = dt.Rows[0]["项目名称"].ToString();
                this.tbxmjm.Text = dt.Rows[0]["项目简码"].ToString();
                this.cbSex.SelectedValue = dt.Rows[0]["适用性别"].ToString();
                this.tbxmfy.Text = dt.Rows[0]["项目费用"].ToString();
                this.tbxmms.Text = dt.Rows[0]["项目描述"].ToString();
            }
        }


    }
}
